package com.nuhu.service;

import com.nuhu.dao.PackageDao;
import com.nuhu.dao.UserDao;
import com.nuhu.pojo.User;
import com.nuhu.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class UserService implements UserServiceImpl {
    @Autowired
    private UserDao userDao;
    @Autowired
    private PackageDao packageDao;
    @Override
    public void registerUser(User user) {
        userDao.insertUser(user);
    }
    @Override
    public boolean loginUser(User user) {
        String storedPassword = userDao.getPasswordByPhoneNumber(user.getPhoneNumber());
        return (user.getPassword()).equals(storedPassword);
    }

    public String getUserNameByPhoneNumber(String phoneNumber) {
        return userDao.getUserNameByPhoneNumber(phoneNumber);
    }

    public String getIdCardNumberByPhoneNumber(String phoneNumber) {
        return userDao.getIdCardNumberByPhoneNumber(phoneNumber);
    }

    public int getPackageIdByPhoneNumber(String phoneNumber) {
        User user = userDao.getUserByPhoneNumber(phoneNumber);
        return user.getPackageId();
    }

    public String getPackageNameById(int packageId) {
        return packageDao.getPackageNameById(packageId);
    }

    public BigDecimal getPackageDataLimitById(int packageId) {return packageDao.getPackageDataLimitById(packageId);}
    public boolean checkPhoneNumberExists(String phoneNumber) {
        // 在 UserDao 中查询手机号是否存在
        return userDao.existsByPhoneNumber(phoneNumber);
    }
    @Override//龚邓坤增加
    public void rechargeBalance(String phoneNumber, BigDecimal amount) {
        userDao.updateBalanceByPhoneNumber(phoneNumber, amount);
    }
    @Override//龚邓坤增加
    public void rechargeData_Balance(String phoneNumber, BigDecimal Data_Balance) {
        userDao.updateData_BalanceByPhoneNumber(phoneNumber, Data_Balance);
    }
    @Override
    public void updateDataBalanceAndPackageId(String phoneNumber, BigDecimal newDataBalance, int newPackageId) {
        userDao.updateDataBalanceAndPackageIdByPhoneNumber(phoneNumber, newDataBalance, newPackageId);
    }
    @Override
    public void phoneUser(int newPackageId, String phoneNumber, String userName, String idCardNumber) {
        userDao.insertPhone(newPackageId, phoneNumber, userName, idCardNumber);
    }
}

